package com.example.studentsystem.db;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;

import com.example.studentsystem.R;

public class StudentList extends AppCompatActivity {
    private Button mStuListbackMain;
    private ListView listView;
    private DBHelper dbHelper;
    private StudentCursorAdapter adapter;
    private Fragment mContentFragment;
    private FragmentManager mFragmentManager;

    @SuppressLint({"MissingInfl atedId", "MissingInflatedId"})
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.student_list);
        mStuListbackMain = findViewById(R.id.StuListbackMain);
        listView = findViewById(R.id.listView);
        mStuListbackMain.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish(); // 关闭当前Activity
                Intent intent = new Intent(StudentList.this, MainInterface.class);
                startActivity(intent);
            }
        });

        dbHelper = new DBHelper(this);
        Cursor cursor = dbHelper.selectAllStudent();
        if (cursor != null && cursor.moveToFirst()) {
            adapter = new StudentCursorAdapter(this, cursor, 0);
            listView.setAdapter(adapter);
        } else {
            Log.e("StudentList", "Cursor is empty or cannot move to first", new Exception("Cursor error"));
        }
    }
}
